}
let _ = shell.verbose(|shell| {
- let _ = handle_cause(error, shell);
+ error.cause().map(|err| {
+ let _ = handle_cause(err, shell);
+ });
Ok(())
});
use core::{Package, PackageId, PackageSet, Target, Resolve};
use util;
-use util::{CargoResult, ProcessBuilder, CargoError, human};
+use util::{CargoResult, ProcessBuilder, CargoError, ChainError, human, caused_human};
use util::{Config, Freshness, internal, ChainError};
use self::job::Job;
});
rustcs.move_iter().map(|rustc| {
+ let name = package.get_name().to_string();
+
Job::new(proc() {
if primary {
log!(5, "executing primary");
- try!(rustc.exec().map_err(|err| human(err.to_string())))
+ try!(rustc.exec().chain_error(|| human(format!("Could not compile `{}`.", name))))
} else {
log!(5, "executing deps");
try!(rustc.exec_with_output().and(Ok(())).map_err(|err| {
- human(err.to_string())
+ caused_human(format!("Could not compile `{}`.\n{}", name, err.output().unwrap()), err)
}))
}
Ok(Vec::new())
None => "never executed".to_string()
};
try!(write!(f, "{} (status={})", self.msg, exit));
+ self.output().map(|out| { let _ = write!(f, "{}", out); });
+ Ok(())
+ }
+}
+
+impl ProcessError {
+ pub fn output(&self) -> Option<String> {
match self.output {
Some(ref out) => {
+ let mut string = String::new();
match str::from_utf8(out.output.as_slice()) {
Some(s) if s.trim().len() > 0 => {
- try!(write!(f, "\n--- stdout\n{}", s));
+ string.push_str("\n--- stdout\n");
+ string.push_str(s);
}
Some(..) | None => {}
}
match str::from_utf8(out.error.as_slice()) {
Some(s) if s.trim().len() > 0 => {
- try!(write!(f, "\n--- stderr\n{}", s));
+ string.push_str("\n--- stderr\n");
+ string.push_str(s);
}
Some(..) | None => {}
}
- }
- None => {}
+ Some(string)
+ },
+ None => None
}
- Ok(())
}
}
is_human: true
} as Box<CargoError + Send>
}
+
+pub fn caused_human<S: Show, E: CargoError + Send>(error: S, cause: E) -> Box<CargoError + Send> {
+ box ConcreteCargoError {
+ description: error.to_string(),
+ detail: None,
+ cause: Some(cause.box_error()),
+ is_human: true
+ } as Box<CargoError + Send>
+}
pub use self::result::{Wrap, Require};
pub use self::errors::{CargoResult, CargoError, BoxError, ChainError, CliResult};
pub use self::errors::{CliError, FromError, ProcessError};
-pub use self::errors::{process_error, internal_error, internal, human};
+pub use self::errors::{process_error, internal_error, internal, human, caused_human};
pub use self::paths::realpath;
pub use self::hex::{to_hex, short_hash};
pub use self::pool::TaskPool;
actual.status.matches_exit_status(code),
format!("exited with {}\n--- stdout\n{}\n--- stderr\n{}",
actual.status,
- str::from_utf8(actual.output.as_slice()),
- str::from_utf8(actual.error.as_slice())))
+ String::from_utf8_lossy(actual.output.as_slice()),
+ String::from_utf8_lossy(actual.error.as_slice())))
}
}
}
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", "invalid rust code!");
- let target = realpath(&p.root().join("target")).assert();
-
assert_that(p.cargo_process("cargo-build"),
execs()
.with_status(101)
{filename}:1:1: 1:8 error: expected item but found `invalid`
{filename}:1 invalid rust code!
^~~~~~~
-Could not execute process \
-`rustc {filename} --crate-name foo --crate-type bin --out-dir {} -L {} -L {}` (status=101)\n",
- target.display(),
- target.display(),
- target.join("deps").display(),
+Could not compile `foo`.
+
+To learn more, run the command again with --verbose.\n",
filename = format!("src{}foo.rs", path::SEP)).as_slice()));
})